<template> 
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选搜索</span>

            </div>
            <div style="margin-top: 15px">
                <el-form :model="searchFrom" :inline="true" size="small" label-width="140px">
                    <el-form-item label="商品分类：">
                        <el-input style="width: 203px" v-model="searchFrom.contentId" placeholder="商品分类"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button
                                style="float: right"
                                @click="handleSearchList()"
                                type="primary"
                                size="small">
                            查询结果
                        </el-button>
                        <el-button
                                style="float: right;margin-right: 15px"
                                @click="handleResetSearch()"
                                size="small">
                            重置
                        </el-button>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <el-card class="operate-container" shadow="never">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
        </el-card>
        <div class="table-container">
            <el-table ref="productTable"
                      :data="list"
                      style="width: 100%;font-size: 14px"
                      @selection-change="handleSelectionChange"
                      v-loading="listLoading"
                      border
                      stripe>
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <el-table-column label="类目ID" align="center">
                    <template slot-scope="scope">{{scope.row.id}}</template>
                </el-table-column>
                <el-table-column label="分类名称" align="center">
                    <template slot-scope="scope">{{scope.row.name}}</template>
                </el-table-column>
                <el-table-column label="排列序号" align="center">
                    <template slot-scope="scope">{{scope.row.sortOrder}}</template>
                </el-table-column>
                <el-table-column label="备注" align="center">
                    <template slot-scope="scope">{{scope.row.remark | RemarkFilter}}</template>
                </el-table-column>
                <el-table-column label="状态" align="center">
                    <template slot-scope="scope">{{scope.row.status | StatusFilter}}</template>
                </el-table-column>
                <el-table-column label="操作" width="300" align="center">
                    <template slot-scope="scope">
                        <p>
                            <el-button
                                    size="mini"
                                    type="primary">
                                查看
                            </el-button>
                            <el-button
                                    size="mini"
                                    type="primary">
                                编辑
                            </el-button>
                            <el-button
                                    size="mini"
                                    type="danger">
                                删除
                            </el-button>
                        </p>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>

    import {itemCatList} from "../../../../api/item";

    export default {
        name: "productList",
        data() {
            return {
                list: [],
                listLoading: true,
                searchFrom: {
                    contentId: ''
                }
            }
        },
        created() {
            // this.getList();
        },
        watch: {},
        filters: {
            StatusFilter(value) {
                if (value == 1) {
                    return '启用';
                } else if (value == 0) {
                    return '禁用';
                }
            },
            RemarkFilter(value) {
                if (value === null){
                    return '暂无'
                }else{
                    return value
                }
            }
        },
        methods: {
            getProductSkuSp(row, index) {
                let spData = JSON.parse(row.spData);
                if (spData != null && index < spData.length) {
                    return spData[index].value;
                } else {
                    return null;
                }
            },
            //获取商品列表
            getList(value) {
                itemCatList(value).then(res => {
                    this.list = res.data.result;
                    this.listLoading = false;
                })
            },

            //查询按钮
            handleSearchList() {
                this.getList(this.searchFrom.contentId)
            },
            //添加商品
            handleAddProduct() {
                this.$router.push({path: '/product/add'});
            },
            handleSizeChange(val) {
                this.getList();
            },
            handleCurrentChange(val) {
                this.getList();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleResetSearch() {
                this.searchFrom.contentId = '';
            },

            //编辑
            handleUpdateProduct(index, row) {
                this.$router.push({path: '/product/update', query: {id: row.id}});
            },

        }
    }
</script>
<style></style>


